import React, { Component} from 'react';
import ReactDOM from 'react-dom';

import './index.css';
class GlobalLoading extends Component {
	constructor (props) {
		super(props);
	}

	render () {
		return (
			<div className="global-loading">
				<div className="global-loading-content">
					<img className="global-loading-content-img" src={require('@/assets/images/loading.gif').default}></img>
					<span>{this.props.tip}</span>
				</div>
			</div>
		);
	}
}



let instance=null;
GlobalLoading.service = function (properties) {
	if (instance) return instance;
	const props = {tip : '加载中，请稍后...',...properties };
	const div = document.createElement('div');
	document.body.appendChild(div);
	ReactDOM.render(React.createElement(GlobalLoading, props), div);
	instance = {
		close () {
			instance = null;
			ReactDOM.unmountComponentAtNode(div);
			document.body.removeChild(div);
		}
	};
	return instance;
};

export default GlobalLoading;
